package oop.db.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import oop.db.Database;

public class SectionQuestionDAO {

	public static void addQuestion(long sectionId, long questionId) throws SQLException {
		Connection conn = null;
		PreparedStatement stmt = null;
		try {
			String sql = "INSERT INTO tblSectionQuestion (sect_id, ques_id) VALUES (?, ?)";
			
			conn = Database.get().getConnection();
			stmt = conn.prepareStatement(sql);
			stmt.setLong(1, sectionId);
			stmt.setLong(2, questionId);
			stmt.executeUpdate();
		} finally {
			if (stmt != null) stmt.close();
			if (conn != null) conn.close();
		}
	}
	
	public static void removeQuestion(long sectionId, long questionId) throws SQLException{
		Connection conn = null;
		PreparedStatement stmt = null;
		try {
			String sql = "DELETE FROM tblSectionQuestion " +
					"WHERE sect_id=? AND ques_id=?";
			
			conn = Database.get().getConnection();
			stmt = conn.prepareStatement(sql);
			stmt.setLong(1, sectionId);
			stmt.setLong(2, questionId);
			stmt.executeUpdate();
		} finally {
			if (stmt != null) stmt.close();
			if (conn != null) conn.close();
		}
	}
	
}
